package com.example.courseselectionsystemconsume.config;

import com.alibaba.fastjson.JSON;
import com.example.courseselectionsystemconsume.pojo.CourseRecord;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ScheduledFuture;

/**
 * @description: TODO
 * @author: Tokyo_God
 * @date: 2021/1/9 10:24
 * Role of:
 * @version: v1.0
 */

/*@Configuration*/
/*@EnableScheduling*/
public class QuartzConfig {

    /*@Resource
    RedisTemplate<String,Object> template;*/

    /*private ScheduledFuture<?> future;*/

    /*@Scheduled(cron = "0/10 * * * * ?")*/
    public void timer(){
        /*System.out.println("正在进入定时器");
        ValueOperations<String,Object> myRedis=template.opsForValue();
        if(myRedis.get("courseRecord")==null){
            System.out.println("消费者redis拿不到courseRecord数据，courseRecord 为null");
        }else{
            String jsonStr= (String) myRedis.get("courseRecord");
            System.out.println("消费者redis拿取缓存:"+jsonStr);
            CourseRecord courseRecord=JSON.parseObject(jsonStr,CourseRecord.class);
            System.out.println("转换成对象后"+courseRecord);
            System.out.println("拿取出来之后正在删除。。。。。。。。。。");
            template.delete("courseRecord");//读取完后删除数据
        }*/

       /* LocalDateTime localDateTime=LocalDateTime.now();
        System.out.println("当前时间为："+localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));*/
    }

}
